from rest_framework.exceptions import APIException


class JsonAPIException(APIException):
    """API Exception"""

    def __init__(self, code='OK', msg='Success', errors=[], status=400):
        self.code = code
        self.msg = 'Msg'
        if isinstance(msg, str):
            self.msg = msg
        else:
            e = getattr(msg, code, None)
            if e:
                self.msg = e.value
        self.errors = errors
        self.status = status

    def __str__(self):
        return '%s:%s' % (self.code, self.msg)